package org.simple.framework.boot.controller;

import org.simple.framework.data.entity.Identifiable;
import org.simple.framework.web.result.exception.web.ParameterException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.io.Serializable;
import java.security.Principal;

/**
 * 项目名称：simple-framework
 * 类名称：ModelGetController
 * 类描述：ModelGetController
 * 创建时间：2018/9/6
 *
 * @author sisyphus   (E-mail:1620657419@qq.com)
 * @version v1.0
 */
public interface ModelGetController<E extends Identifiable<ID>, ID extends Serializable> extends ModelController<E, ID> {

    void handleGet(Principal principal);

    @GetMapping("/{id}")
    default E get(@PathVariable("id") ID id, Principal principal) {
        handleGet(principal);
        return getRepository().findById(id).orElseThrow(ParameterException::new);
    }

}
